package com.ylbh.modules.notice.controller;

import com.ylbh.common.pojo.notice.dto.ArticleDTO;
import com.ylbh.common.pojo.notice.vo.ArticleClassVO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.notice.entity.ShoppingArticle;
import com.ylbh.modules.notice.service.ShoppingArticleService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 *
 * 商城公告
 * @author czx
 * @date 2019-09-03 17:23:24
 */
@RestController
@RequestMapping("notice")
public class ShoppingArticleController {
    @Autowired
    private ShoppingArticleService shoppingArticleService;

    @ApiOperation("商城公告列表")
    @GetMapping("queryNoticeList")
    @RequiresPermissions("notice:queryNoticeList")
    public CommonResult queryNoticeList(PageDTO pageDTO) {
        PageUtils page = shoppingArticleService.queryNoticeList(pageDTO);
        return Ref.ok(page);
    }

    @ApiOperation("删除公告")
    @PostMapping("removeNoticeById")
    @RequiresPermissions("notice:removeNoticeById")
    public CommonResult removeNoticeById(@RequestBody String[] ids) {
        shoppingArticleService.removeNoticeById(Arrays.asList(ids));
        return Ref.ok();
    }

    @ApiOperation("公告详情")
    @GetMapping("getNoticeById/{id}")
    @RequiresPermissions("notice:getNoticeById")
    public CommonResult getNoticeById(@PathVariable String id) {
        ShoppingArticle vo = shoppingArticleService.getNoticeById(id);
        return Ref.ok(vo);
    }

    @ApiOperation("修改公告")
    @PostMapping("modifyNoticeById")
    @RequiresPermissions("notice:modifyNoticeById")
    public CommonResult modifyNoticeById(@RequestBody ArticleDTO articleDTO) {
        shoppingArticleService.modifyNoticeById(articleDTO);
        return Ref.ok();
    }

    @ApiOperation("新增公告")
    @PostMapping("addNotice")
    @RequiresPermissions("notice:addNotice")
    public CommonResult addNotice(@RequestBody ArticleDTO articleDTO) {
        shoppingArticleService.addNotice(articleDTO);
        return Ref.ok();
    }

    @ApiOperation("公告分类")
    @GetMapping("getArticleClass")
    public CommonResult getArticleClass() {
        List<ArticleClassVO> list = shoppingArticleService.getArticleClass();
        return Ref.ok(list);
    }


}
